//
//  DepoistVC.swift
//  d11
//
//  Created by peale on 2018/10/20.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit
import SwiftyJSON
class DepoistVC: BXBaseVC,UITableViewDelegate,UITableViewDataSource,Pay {
   func pay(data: [String : Any], name: String, card: String) {
        print("data:\(data)")
        self.showLoadHUD(title: "提交中...")
        let forparam = data["formparam"] as? [String:Any] ?? [:]
        let dno = forparam["dno"] as? String ?? ""
        let expressCardAmount = forparam["expressCardAmount"] as? String ?? ""
        let ppid = forparam["ppid"] as? String ?? ""
        NetWorkRequest(API.xPayDeposit(url: "324649c", expressCardNum: card, dno: dno, expressCardAmount: expressCardAmount, expressCardName: name, ppid: ppid), completion: { (responseData,statusCode,strData) -> (Void) in
            self.dismissLoadHUD()
            let dataDict = responseData["data"].dictionaryObject ?? [:]
            DispatchQueue.main.async {
                let tempUrl = dataDict["url"] as? String
                var isExit = false
                for (_ , value) in tempUrl!.enumerated(){
                    if("\u{4e00}" <= value && value <= "\u{9fa5}"){
                        isExit = true
                        break
                    }
                }
                var urlString : String? = ""
                if(isExit){
                    urlString = (tempUrl)?.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)
                }else{
                    urlString = tempUrl
                }
                
                if urlString != nil{
                    if urlString?.contains("http") == false{
                        UIHelper.alertSimpleMessage(about: "当前跳转地址异常!", withDescription: "", in: self)
                        return
                    }
                    if let url = URL(string: urlString ?? "") {
                        //根据iOS系统版本，分别处理
                        if #available(iOS 10, *) {
                            UIApplication.shared.open(url, options: [:],
                                                      completionHandler: {
                                                        (success) in
                            })
                            //                                     UIApplication.shared.openURL(url)
                        } else {
                            UIApplication.shared.openURL(url)
                        }
                    }
                }else{
                    UIHelper.alertSimpleMessage(about: "当前跳转地址异常 ", withDescription: "", in: self)
                }
            }
        }, failed: { (faildInfo,reCode,msg) -> (Void) in
            self.dismissLoadHUD()
            DispatchQueue.main.async {
                UIHelper.alertSimpleMessage(about: "\(faildInfo)", withDescription: "", in: self)
            }
        }) { () -> (Void) in
            self.dismissLoadHUD()
            DispatchQueue.main.async {
                UIHelper.alertSimpleMessage(about: "提交存款异常!", withDescription: "", in: self)
            }
        }
    }
    
    let  reuseIdentifierID : String = "DepoistTopHintCell"
    let  reuseIdentifierID2 : String = "DepoistInputItemCell"
    let  reuseIdentifierID3 : String = "DepoistBackCell"
    let  reuseIdentifierID4 : String = "DepoistBtnCell"
    let  reuseIdentifierID5 : String = "DepoistSelectCell"
    let  reuseIdentifierID6 : String = "DepoistHintCell"
    let  reuseIdentifierID7 : String = "DepoistSelectCell"
    let  reuseIdentifierID8 : String = "DepoistInputInfoCell"
    let  reuseIdentifierHeadID : String = "DepoistHeadView"
    var moneyCount:String = "" //充值的金额
    var realName :String?   //真实姓名
    var bankNo :String?    //银行卡号
    var isTopMin : Bool = false  //是否是只有一个输入框(true 还有按钮)
    var pageType : Int = 0  //0:提示->输入->按钮 || 1.输入->支付通道->按钮|| 2.输入->信息输入->支付通道->付款银行历史->按钮
    var isTopHaveHint : Bool = false  //是否显示顶部充值金额输入提示
    var isHaveHint : Bool = false  //是否显示温馨提示
    var payCount : Int = 0             //支付通道数量
    var historyCount :Int = 0           //付款银卡历史数量
    var paySelectIndex : Int = -1         //支付通道选择下标
    var historySelectIndex : Int = -1         //付款银卡历史选择下标
    
    var depoistList :[[String:Any]]? //三方/bq/fy存款数据
    var isDepoistInput : Bool = false //是否是显示输入
    var isDepoistBQ : Bool = false //是否是bq 废弃
    var isDepoistAA : Bool = false //是否是aa 废弃
    var isDepoistInputInfo : Bool = false //是否是输入信息
    var isbq : String = "0" //是否是bq
    var bankList:[[String:Any]]? //数据列表
    var bankDetails:String? //支付详情
    var bankType:String?  //支付类型
    var submitBtn : UIButton?
    var moneyBtnArray:[String]?
    var isShowPop :Bool = true //是否显示支付提示
    var isShowBankInfoPop : Bool = true //是否显示银行信息支付提示
    
    var limitMin:String? //第三方的最低取款限额
    var limitMax:String? //第三方的最高取款限额
    var params:[String:Any]? // 银行信息支付
    var isBack : Bool = false
    var isBank : Bool = false //是否是银行列表
    var isOneUserName = false //只输入名称
    override func currentViewControllerShouldPop() -> Bool {
        self.isBack  = true
        
        return true
    }
    lazy var tableView:UITableView = {
        let table = UITableView(frame:CGRect(x: 0, y: 0, width: self.view.width, height:kScreenHeight-kTabBarBottom-60), style:UITableView.Style.plain)
        table.dataSource = self
        table.delegate = self
        //table.layoutMargins = UIEdgeInsets.zero
        table.separatorStyle = .none
        table.backgroundColor  = UIColor.white
        table.showsVerticalScrollIndicator = false
        table.tableFooterView = UIView.init()
        table.separatorStyle = .none
        table.autoresizingMask = [.flexibleWidth,.flexibleHeight]
        table.estimatedRowHeight = 0
        table.estimatedSectionHeaderHeight = 0
        table.estimatedSectionFooterHeight = 0
//        if #available(iOS 11.0, *) {
//            table.contentInsetAdjustmentBehavior = .never
//        } else {
//            self.automaticallyAdjustsScrollViewInsets = false
//        }
        return table
    }()
    func initSubmitBtn() -> Void {
        self.submitBtn  = UIButton.init(type: .custom)
        self.submitBtn?.setTitle("提交", for: .normal)
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: kScreenWidth-20, height: 50)
        self.submitBtn?.layer.addSublayer(layerGradient)
        self.submitBtn?.layer.cornerRadius = 5;
        self.submitBtn?.layer.masksToBounds = true
        self.submitBtn?.addTarget(self, action: #selector(self.actionToDepoistSubmit), for: .touchUpInside)
        self.view.addSubview(self.submitBtn!)
        self.submitBtn?.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(50)
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-(kTabBarBottom+10))
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // 设置导航栏默认返回按钮
        self.leftButtonActionWithImg("icon_default_back")
        
        self.navigationItem.titleView = UIImageView.init(image: UIImage.init(named: "navi_icon_titleLogo"))
        self.navigationController?.navigationBar.shadowImage = UIImage()
        
        self.title = ""
        
        
        if self.depoistList == nil{
            self.payCount = 0
            self.paySelectIndex = -1
        }else {
            self.payCount = (self.depoistList?.count)! //通道数量
            self.paySelectIndex = 0
        }
        
        self.moneyBtnArray = GlobalInfo.moneyButton
        if self.moneyBtnArray == nil {
            self.moneyBtnArray = []
        }
        self.view.backgroundColor = UIColor.white
        self.view.addSubview(self.tableView)
        self.initSubmitBtn()
        if(self.depoistList != nil){
            let tempModel = self.depoistList?[0]
                   let tempDict = tempModel?["showInfo"] as? [String:Any] ?? [String:Any]()
                   let keyType = tempDict["keyType"] as? String ?? ""
                   let dataDict = tempModel?[keyType] as? [String : Any] ?? [:]
                   let bqoption : String = dataDict["bqoption"] as? String ?? ""
                  let bankLogo = dataDict["banklogo"] as? String ?? ""
                   self.isOneUserName = false
                   if(keyType == "6" && bankLogo == "logo-PAYCARD" && self.isDepoistInputInfo)
                       || (bqoption == "2" && bankLogo != "logo-ZFB" && self.isDepoistInputInfo)
                       || (bqoption == "3" && self.isDepoistInputInfo || (bqoption == "4" && keyType == "23") || (bqoption == "5" && keyType == "23")){
                       self.pageType = 2
                       self.isDepoistInput = true
                   }else if  (bqoption == "2" && bankLogo == "logo-ZFB" && self.isDepoistInputInfo){
                       self.pageType = 2
                       self.isOneUserName = true
                       self.isDepoistInput = true
                   }else{
                       self.pageType = 1
                       self.isDepoistInput = false
                   }
                   self.tableView.reloadData()
        }
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        if  self.pageType == 0 {  //只有输入+提交
            return 2
        }else if pageType == 1{ //支付通道
            return 3
        }else if pageType == 2{ //信息输入
            return 4
        }
        return 0
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {  //顶部输入 //1.只有提示+输入或者2.还有4个按钮的+提示
            if self.isTopHaveHint == true{
                return 2
            }
            return 1
        }else if section == 1{ //中间的 提示和返回重新选择存款方式
            if isHaveHint == true{  //有提示
                return 1
            }
            return 0
        }else if section == 2{ //1.支付通道。或者2.信息输入 3.提交
            if self.pageType == 1{ //支付通道
                return payCount //通道数量
            }else if self.pageType == 2{ //信息输入
                if self.isOneUserName == true{ //真实姓名
                    return 1
                }
                return 2  //真是姓名/ 银行卡号
            }
            return 1
        }else if section == 3 {  //1. 支付通道  2.提交  1或者n个
            if self.pageType == 2{
                return payCount //通道数量
            }
            return 1
        }else if section == 4{  //2.付款银行历史  n个
            return historyCount
        }
        return 0
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.section == 0{
            if self.isTopHaveHint == true{
                if indexPath.row == 0 { //提示
                    return 35
                }else if indexPath.row == 1{  //输入
                    if self.isTopMin == true{
                        return 115
                    }else{
                        return 215
                    }
                }
            }else{
                if self.isTopMin == true{ //0没有btn
                    return 115
                }else{
                    return 215
                }
            }
        }else if indexPath.section == 1{
            if isHaveHint == true{
                if indexPath.row == 0 { //提示
                    return 30
                }
                //                else if indexPath.row == 1{  //返回重新选择
                //                    return 60
                //                }
            }
            //            else{
            //                if indexPath.row == 0 {  //返回重新选择
            //                    return 60
            //                }
            //            }
        }else if indexPath.section == 2 {
            //            if self.pageType == 0 {  //提交
            //                return 80
            //            }else
            if self.pageType == 1{ //支付通道
                return 60
            }else if self.pageType == 2{ //信息输入
                return 60
            }
        }else if indexPath.section == 3 {
            //            if self.pageType == 1{ //提交
            //                return 80
            //            }else
            if self.pageType == 2{//支付通道
                return 60
            }
        }else if indexPath.section == 4 {
            if self.pageType == 2{ //付款银行历史
                return 60
            }
        }
        //        else if indexPath.section == 5 {
        //            if self.pageType == 2{ //提交
        //                return 80
        //            }
        //        }
        
        return 0
    }
    
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        if (section == 2&&self.pageType == 1) || (section == 3&&self.pageType == 2) || (section == 4&&self.pageType == 2){
            var headerView : DepoistHeadView? =  (tableView.dequeueReusableHeaderFooterView(withIdentifier: reuseIdentifierHeadID as String) as? DepoistHeadView)
            if headerView == nil {
                headerView = DepoistHeadView(reuseIdentifier: reuseIdentifierHeadID as String)
            }
            var title :String = ""
            if (section == 2&&self.pageType == 1) || (section == 3&&self.pageType == 2){
                title = "支付通道"
            }else  if (section == 4&&self.pageType == 2){
                title = "付款银行历史"
                
            }
            headerView?.setData(title: title)
            return headerView
        }else{
            return UITableViewHeaderFooterView.init()
        }
        
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if (section == 2&&self.pageType == 1) || (section == 3&&self.pageType == 2) || (section == 4&&self.pageType == 2){
            if (section == 2&&self.pageType == 1) || (section == 3&&self.pageType == 2){
                if payCount > 0{
                    return 40.5
                }else{
                    return 0
                }
                
            }
            return 40.5
        }
        return 0
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.section == 0 {
            if self.isTopHaveHint == true{
                if indexPath.row == 0{ //提示
                    var cell :DepoistTopHintCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID as String) as? DepoistTopHintCell
                    if cell == nil {
                        cell =  DepoistTopHintCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID as String)
                    }
                    return cell!
                }else{ //输入框
                    if self.isTopMin == true  //小的
                    {
                        var cell :DepoistInputItemCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID2 as String) as? DepoistInputItemCell
                        if cell == nil {
                            cell =  DepoistInputItemCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID2 as String)
                        }
                        cell?.callChangeBlock({ (text) in
                            self.moneyCount = text
                        })
                        
                        cell?.setData(money:self.moneyCount)
                        return cell!
                    }else{
                        //大的
                        var cell :DepoistInputItem2Cell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID2 as String) as? DepoistInputItem2Cell
                        if cell == nil {
                            cell =  DepoistInputItem2Cell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID2 as String)
                        }
                        cell?.callChangeBlock({ (text,type) in
                            self.moneyCount = text
                        })
                        
                        let tempModel = self.depoistList?[self.paySelectIndex]
                        let tempDict = tempModel?["showInfo"] as? [String:Any] ?? [String:Any]()
                        let keyType = tempDict["keyType"] as? String ?? ""
                        let dataDict = tempModel?[keyType] as? [String:Any] ?? [String:Any]()
                        cell?.setData(money: self.moneyCount, array: self.moneyBtnArray!,rangeLimit:dataDict["rangeLimit"] as? String ?? "")
                        return cell!
                    }
                }
            }else
            { //输入框
                if self.isTopMin == true  //小的
                {
                    var cell :DepoistInputItemCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID2 as String) as? DepoistInputItemCell
                    if cell == nil {
                        cell =  DepoistInputItemCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID2 as String)
                    }
                    cell?.callChangeBlock({ (text) in
                        self.moneyCount = text
                    })
                    
                    cell?.setData(money:self.moneyCount)
                    return cell!
                }else{
                    //大的
                    var cell :DepoistInputItem2Cell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID2 as String) as? DepoistInputItem2Cell
                    if cell == nil {
                        cell =  DepoistInputItem2Cell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID2 as String)
                    }
                    cell?.callChangeBlock({ (text,type) in
                        self.moneyCount = text
                        
                    })
                    let tempModel = self.depoistList?[self.paySelectIndex]
                    let tempDict = tempModel?["showInfo"] as? [String:Any] ?? [String:Any]()
                    let keyType = tempDict["keyType"] as? String ?? ""
                    let dataDict = tempModel?[keyType] as? [String:Any] ?? [String:Any]()
                    cell?.setData(money: self.moneyCount, array: self.moneyBtnArray!,rangeLimit:dataDict["rangeLimit"] as? String ?? "")
                    return cell!
                }
                
            }
        }else if indexPath.section == 1{
            if isHaveHint == true{
                if indexPath.row == 0{ //提示
                    var cell : DepoistHintCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID6 as String) as? DepoistHintCell
                    if cell == nil {
                        cell =  DepoistHintCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID6 as String)
                    }
                    return cell!
                }else{ //重新选择返回
                    var cell : DepoistBackCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID3 as String) as? DepoistBackCell
                    if cell == nil {
                        cell =  DepoistBackCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID3 as String)
                    }
                    return cell!
                }
            }else{
                var cell : DepoistBackCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID3 as String) as? DepoistBackCell
                if cell == nil {
                    cell =  DepoistBackCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID3 as String)
                }
                return cell!
            }
        }else if indexPath.section == 2{
            //            if self.pageType == 0{ //提交
            //                var cell : DepoistBtnCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID4 as String) as? DepoistBtnCell
            //                if cell == nil {
            //                    cell =  DepoistBtnCell(style: UITableViewCellStyle.default, reuseIdentifier: reuseIdentifierID4 as String)
            //                    cell?.submitBtn?.addTarget(self, action: #selector(self.actionToSubmit),for: .touchUpInside)
            //                }
            //
            //                return cell!
            //            }else
            if pageType == 1{ //支付通道
                var cell :DepoistSelectCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID7 as String) as? DepoistSelectCell
                if cell == nil {
                    cell =  DepoistSelectCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID7 as String)
                }
                var isBottom = false
                var isSelect = false
                if indexPath.row == self.payCount-1{
                    isBottom = true
                }
                if indexPath.row == self.paySelectIndex{
                    isSelect = true
                }
                let depoistDict = self.depoistList?[indexPath.row]
                
                cell?.setData(dict: depoistDict?["showInfo"] as? [String : Any] ?? [:], isBottom: isBottom, isSelect: isSelect, row: indexPath.row,channel: 0,isBank:self.isBank)
                return cell!
            }else if pageType == 2{ //信息输入
                var cell :DepoistInputInfoCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID8 as String) as? DepoistInputInfoCell
                if cell == nil {
                    cell =  DepoistInputInfoCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID8 as String)
                }
                cell?.callChangeBlock({ (info, row) in
                    if(row == 0){
                        self.realName = info
                    }else if(row == 1){
                        self.bankNo = info
                    }
                })
                if indexPath.row == 0{  //真是姓名
                    cell?.setData(inputText: self.realName ?? "", row: 0, isBottom: false)
                }else if indexPath.row == 1{ // 银行卡号
                    cell?.setData(inputText: self.bankNo ?? "", row: 1, isBottom: true)
                }
                return cell!
            }
        }else if indexPath.section == 3{
            if pageType == 2{ //支付通道
                var cell :DepoistSelectCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID7 as String) as? DepoistSelectCell
                if cell == nil {
                    cell =  DepoistSelectCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID7 as String)
                }
                var isBottom = false
                var isSelect = false
                if indexPath.row == self.payCount-1{
                    isBottom = true
                }
                if indexPath.row == self.paySelectIndex{
                    isSelect = true
                }
                let depoistDict = self.depoistList?[indexPath.row]
                cell?.setData(dict: depoistDict?["showInfo"] as? [String : Any] ?? [:], isBottom: isBottom, isSelect: isSelect, row: indexPath.row,channel: 0,isBank: self.isBank)
                
                return cell!
            }else{
                //                if self.pageType == 1{ //提交
                //                    var cell : DepoistBtnCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID4 as String) as? DepoistBtnCell
                //                    if cell == nil {
                //                        cell =  DepoistBtnCell(style: UITableViewCellStyle.default, reuseIdentifier: reuseIdentifierID4 as String)
                //                        cell?.submitBtn?.addTarget(self, action: #selector(self.actionToSubmit),for: .touchUpInside)
                //                    }
                //                    return cell!
                //                }
            }
        }else if indexPath.section == 4{
            if pageType == 2{ //付款银行历史
                var cell :DepoistSelectCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID7 as String) as? DepoistSelectCell
                if cell == nil {
                    cell =  DepoistSelectCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID7 as String)
                }
                var isBottom = false
                var isSelect = false
                if indexPath.row == self.historyCount-1{
                    isBottom = true
                }
                if indexPath.row == self.historySelectIndex{
                    isSelect = true
                }
                //  cell?.setData(dict:[:], isBottom: isBottom, isSelect: isSelect, row: indexPath.row)
                return cell!
            }
        }
        //else if indexPath.section == 5{
        //            if pageType == 2{ //提交
        //                var cell : DepoistBtnCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID4 as String) as? DepoistBtnCell
        //                if cell == nil {
        //                    cell =  DepoistBtnCell(style: UITableViewCellStyle.default, reuseIdentifier: reuseIdentifierID4 as String)
        //                    cell?.submitBtn?.addTarget(self, action: #selector(self.actionToSubmit),for: .touchUpInside)
        //                }
        //                return cell!
        //            }
        //       }
        return UITableViewCell.init()
    }
    
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if (indexPath.section == 2&&self.pageType == 1) || (indexPath.section == 3&&self.pageType == 2) {//支付通道
            self.paySelectIndex  =  indexPath.row
            let tempModel = self.depoistList?[indexPath.row]
            let tempDict = tempModel?["showInfo"] as? [String:Any] ?? [String:Any]()
            let keyType = tempDict["keyType"] as? String ?? ""
            let dataDict = tempModel?[keyType] as? [String : Any] ?? [:]
            let bankLogo = dataDict["banklogo"] as? String ?? ""
            let bqoption : String = dataDict["bqoption"] as? String ?? ""
            self.isOneUserName = false
            if(keyType == "6" && bankLogo == "logo-PAYCARD" && self.isDepoistInputInfo)
                || (bqoption == "2" && bankLogo != "logo-ZFB" && self.isDepoistInputInfo)
                || (bqoption == "3" && self.isDepoistInputInfo || (bqoption == "4" && keyType == "23") || (bqoption == "5" && keyType == "23")){
                self.pageType = 2
                self.isDepoistInput = true
            }else if  (bqoption == "2" && bankLogo == "logo-ZFB" && self.isDepoistInputInfo){
                self.pageType = 2
                self.isOneUserName = true
                self.isDepoistInput = true
            }else{
                self.pageType = 1
                self.isDepoistInput = false
            }
            self.tableView.reloadData()
        }
        
        if indexPath.section == 4 && pageType == 2{//付款银行历史
            self.historySelectIndex  =  indexPath.row
            self.tableView.reloadData()
        }
        
    }
    
    //提交信息
    @objc func actionToDepoistSubmit() -> Void {
        if self.depoistList == nil {
            UIHelper.alertSimpleMessage(about: "支付通道数据异常!", withDescription: "", in: self)
            return
        }
        if self.moneyCount == nil || self.moneyCount == "0" ||  self.moneyCount == "" {
            UIHelper.alertSimpleMessage(about: "请输入金额!", withDescription: "", in: self)
            return
        }
        let tempModel = self.depoistList?[self.paySelectIndex]
        let tempDict = tempModel?["showInfo"] as? [String:Any] ?? [String:Any]()
        let keyType = tempDict["keyType"] as? String ?? ""
        let dataDict = tempModel?[keyType] as? [String : Any] ?? [:]
        let bankLogo = dataDict["banklogo"] as? String ?? ""
        let bqoption : String = dataDict["bqoption"] as? String ?? ""
        if(keyType == "6" && bankLogo == "logo-PAYCARD" && self.isDepoistInputInfo)
            || (bqoption == "2" && bankLogo != "logo-ZFB" && self.isDepoistInputInfo)
            || (bqoption == "3" && self.isDepoistInputInfo || (bqoption == "4" && keyType == "23") || (bqoption == "5" && keyType == "23")){
            if self.realName == nil || self.realName == "" {
                UIHelper.alertSimpleMessage(about: "请输入存款人真实姓名!", withDescription: "", in: self)
                return
            }
            if self.bankNo == nil  || self.bankNo == "" {
                UIHelper.alertSimpleMessage(about: "请输入银行卡号!", withDescription: "", in: self)
                return
            }
            if (self.bankNo?.count)! < 6 {
                UIHelper.alertSimpleMessage(about: "银行卡号错误!", withDescription: "", in: self)
                return
            }
        }else if (bqoption == "2" && bankLogo == "logo-ZFB" && self.isDepoistInputInfo){
            if self.realName == nil || self.realName == "" {
                UIHelper.alertSimpleMessage(about: "请输入存款人真实姓名!", withDescription: "", in: self)
                return
            }
        }
        //处理金额
        let  rangeLimit = dataDict["rangeLimit"] as? String ?? ""
        let limitArray =  rangeLimit.components(separatedBy: ",")
        if limitArray.count >= 1{
            let mindeposit =  limitArray[0]
            if ToolHelper.isPurnFloat(string: mindeposit) == true{
                if Double(self.moneyCount)! <  Double(mindeposit)!{
                    UIHelper.alertSimpleMessage(about: "存款金额不能小于\(mindeposit)!", withDescription: "", in: self)
                    return
                }
            }
        }
        
        if limitArray.count >= 2{
            let maxdeposit =  limitArray[1]
            if ToolHelper.isPurnFloat(string: maxdeposit) == true{
                if Double(self.moneyCount)! > Double(maxdeposit)!{
                    UIHelper.alertSimpleMessage(about: "存款金额不能大于\(maxdeposit)!", withDescription: "", in: self)
                    return
                }
            }
        }
        
        self.showLoadHUD(title: "提交中...")
        let optionid = dataDict["optionid"] as? String ?? ""
        NetWorkRequest(API.paymentDepoist(url: "f0c41aa", bqoption: dataDict["bqoption"] as? String ?? "", optionid: optionid,banklogo:dataDict["banklogo"] as? String ?? "", amount: self.moneyCount, payCardNumber: self.bankNo ?? "", payUserName: self.realName ?? ""), completion: { (responseData,statusCode,strData) -> (Void) in
            self.dismissLoadHUD()
            DispatchQueue.main.async {
                let dataDict = responseData["data"].dictionaryObject ?? [:]
                if(optionid == "8"){
                    let formparam = dataDict["formparam"] as? [String:Any] ?? [:]
                    if(formparam.count>0){
                        let payView = XPayView.init(data: dataDict)
                        payView.delegate = self
                        return

                    }
//                    let ppid = formparam["ppid"] as? String ?? ""
//                    if("3033,3035,3048,3050".contains(ppid)){
//                    }
                }
                let method = dataDict["method"] as? Int ?? -1
                if method == 1{
                    print("数据啊\(dataDict)")
                    let url = dataDict["url"] as? String
                    if url != nil{
                        let array : Array = url!.components(separatedBy: "&")
                        if array.count >= 4{
                            let title = array[0].replacingOccurrences(of: "title=", with: "")
                            var base64Params = array[1].replacingOccurrences(of: "content=", with: "")
                            let msg = array[2].replacingOccurrences(of: "msg=", with: "")
                            let amt = array[3].replacingOccurrences(of: "amt=", with: "")
                            if base64Params.count>0&&base64Params.count%4 != 0{
                                let paramsNum = base64Params.count%4
                                for _ in 0 ... (4-paramsNum){
                                    base64Params.append("=")
                                }
                            }
                            let decodedParamsData = NSData(base64Encoded: base64Params, options: NSData.Base64DecodingOptions(rawValue: 0))
                            if decodedParamsData != nil{
                                let decodedParams = NSString(data: decodedParamsData! as Data, encoding: String.Encoding.utf8.rawValue)
                                print("\(decodedParams)")
                                print("\(decodedParams?.removingPercentEncoding ?? "")")
                                let urlstring : String = decodedParams?.removingPercentEncoding ?? ""
                                let vc =  DepoistQRCodeVC.init()
                                vc.urlString = urlstring
                                vc.titleString = title
                                vc.msgString = msg
                                vc.amtString = amt
                                self.navigationController?.pushViewController(vc, animated: true)
                            }else{
                                UIHelper.alertSimpleMessage(about: "内容数据解析异常!", withDescription: "", in: self)
                            }
                        }else{
                            UIHelper.alertSimpleMessage(about: "参数数据解析异常!", withDescription: "", in: self)
                        }
                    }else{
                        UIHelper.alertSimpleMessage(about: "url地址异常!", withDescription: "", in: self)
                    }
                }else
                    if method == 2{
                        if self.isDepoistBQ == true && keyType == "6" && bankLogo == "logo-PAYCARD"{
                            self.params = dataDict
                            self.showBankInfoPopView()
                        }else  if self.isDepoistAA == true && keyType == "6"{
                            self.params = dataDict
                            self.showBankInfoPopView()
                        }else if keyType == "6"{
                            self.params = dataDict
                            self.showBankInfoPopView()
                        }else{
                            let tempUrl = dataDict["url"] as? String
                            var isExit = false
                            for (_ , value) in tempUrl!.enumerated(){
                                if("\u{4e00}" <= value && value <= "\u{9fa5}"){
                                    isExit = true
                                    break
                                }
                            }
                            var urlString : String? = ""
                            if(isExit){
                                urlString = (tempUrl)?.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)
                            }else{
                                urlString = tempUrl
                            }
                            
                            if urlString != nil{
                                if urlString?.contains("http") == false{
                                    UIHelper.alertSimpleMessage(about: "当前跳转地址异常!", withDescription: "", in: self)
                                    return
                                }
                                if let url = URL(string: urlString ?? "") {
                                    //根据iOS系统版本，分别处理
                                    if #available(iOS 10, *) {
                                        UIApplication.shared.open(url, options: [:],
                                                                  completionHandler: {
                                                                    (success) in
                                        })
                                        //                                     UIApplication.shared.openURL(url)
                                    } else {
                                        UIApplication.shared.openURL(url)
                                    }
                                }
                            }else{
                                UIHelper.alertSimpleMessage(about: "当前跳转地址异常 \(method)!", withDescription: "", in: self)
                            }
                        }
                    }else if method == 3{//post请求提交
                        let url = dataDict["url"] as? String
                        if url != nil{
                            let array : Array = url!.components(separatedBy: "&")
                            if array.count >= 2{
                                var base64Url = array[0].replacingOccurrences(of: "url=", with: "")
                                var base64Params = array[1].replacingOccurrences(of: "params=", with: "")
                                if base64Url.count>0&&base64Url.count%4 != 0{
                                    let urlNum = base64Url.count%4
                                    for _ in 0 ... (4-urlNum){
                                        base64Url.append("=")
                                    }
                                }
                                
                                let decodedUrlData = NSData(base64Encoded: base64Url, options: NSData.Base64DecodingOptions(rawValue: 0))
                                if decodedUrlData != nil {
                                    let decodedUrl = NSString(data: decodedUrlData! as Data, encoding: String.Encoding.utf8.rawValue)
                                    if base64Params.count>0&&base64Params.count%4 != 0{
                                        let paramsNum = base64Params.count%4
                                        for _ in 0 ... (4-paramsNum){
                                            base64Params.append("=")
                                        }
                                    }
                                    let decodedParamsData = NSData(base64Encoded: base64Params, options: NSData.Base64DecodingOptions(rawValue: 0))
                                    if decodedParamsData != nil{
                                        let decodedParams = NSString(data: decodedParamsData! as Data, encoding: String.Encoding.utf8.rawValue)
                                        UserDefaults.standard.set(decodedUrl, forKey: DefaultKey.THIRD_PARTY_DOMAIN)
                                        let paramsDict  =  JSON.init(parseJSON: decodedParams! as String).dictionaryObject
                                        if paramsDict == nil{
                                            UIHelper.alertSimpleMessage(about: "json数据解析异常!", withDescription: "", in: self)
                                        }else{
                                            var htmlText = "<html><body><form id=\"paySubmit\" name=\"paySubmit\" action=\"\(decodedUrl ?? "")\" method=\"post\">"
                                            for (key, value) in paramsDict! {
                                                htmlText.append(contentsOf: "<input type=\"hidden\" name=\"\(key)\" value=\"\(value)\" />")
                                            }
                                            htmlText.append(contentsOf: "</from></body><script>document.paySubmit.submit();</script></html>;")
                                            self.navigationController?.navigationItem.backBarButtonItem?.title = ""
                                            let vc = HtmlWebVC()
                                            vc.navigationController?.navigationItem.backBarButtonItem?.title = ""
                                            vc.htmlDataStr = htmlText
                                            self.navigationController?.pushViewController(vc, animated: true)
                                        }
                                        //   print("\(decodedUrl ?? "异常")---\(decodedParams ?? "异常")---\(paramsDict)")
                                    }else{
                                        UIHelper.alertSimpleMessage(about: "参数数据解析异常!", withDescription: "", in: self)
                                    }
                                }else{
                                    UIHelper.alertSimpleMessage(about: "地址数据解析异常!", withDescription: "", in: self)
                                }
                                
                                
                            }else{
                                if url?.hasPrefix("content=") ?? false{ //判断开始是不是content=
                                    print("是的")
                                    var base64Content = url!.replacingOccurrences(of: "content=", with: "")
                                    if base64Content.count>0&&base64Content.count%4 != 0{
                                        let paramsNum = base64Content.count%4
                                        for _ in 0 ... (4-paramsNum){
                                            base64Content.append("=")
                                        }
                                    }
                                    let decodedParamsData = NSData(base64Encoded: base64Content, options: NSData.Base64DecodingOptions(rawValue: 0))
                                    if decodedParamsData != nil{
                                        let decodedContent = NSString(data: decodedParamsData! as Data, encoding: String.Encoding.utf8.rawValue)
                                        
                                        var htmlstring : String = decodedContent?.removingPercentEncoding ?? ""
                                        htmlstring = htmlstring.replacingOccurrences(of: "+", with: " ")
                                        print("\(htmlstring)")
                                        self.navigationController?.navigationItem.backBarButtonItem?.title = ""
                                        let vc = HtmlWebVC()
                                        vc.navigationController?.navigationItem.backBarButtonItem?.title = ""
                                        vc.htmlDataStr = "<html><body>" + htmlstring + "</body></html>"
                                        self.navigationController?.pushViewController(vc, animated: true)
                                    }
                                }else{
                                    UIHelper.alertSimpleMessage(about: "数据处理异常!", withDescription: "", in: self)
                                }
                                
                            }
                        }else{
                            UIHelper.alertSimpleMessage(about: "url地址异常!", withDescription: "", in: self)
                        }
                    }else{
                        UIHelper.alertSimpleMessage(about: "App当前版本不支持这种支付类型 \(method)!", withDescription: "", in: self)
                }
            }
        }, failed: { (faildInfo,reCode,msg) -> (Void) in
            self.dismissLoadHUD()
            DispatchQueue.main.async {
                UIHelper.alertSimpleMessage(about: "\(faildInfo)", withDescription: "", in: self)
            }
        }) { () -> (Void) in
            self.dismissLoadHUD()
            DispatchQueue.main.async {
                UIHelper.alertSimpleMessage(about: "提交存款异常!", withDescription: "", in: self)
            }
        }
        
    }
    
    
    //    @objc func actionToSubmit() -> Void {
    //
    //        if self.depoistList == nil {
    //            UIHelper.alertSimpleMessage(about: "数据不存在!", withDescription: "", in: self)
    //            return
    //        }
    //        if self.moneyCount == nil || self.moneyCount == "0" {
    //            UIHelper.alertSimpleMessage(about: "请输入金额!", withDescription: "", in: self)
    //            return
    //        }
    //        if(self.pageType == 2){
    //            if self.realName == nil {
    //                UIHelper.alertSimpleMessage(about: "请输入存款人真实姓名!", withDescription: "", in: self)
    //                return
    //            }
    //            if self.bankNo == nil {
    //                UIHelper.alertSimpleMessage(about: "请输入银行卡号!", withDescription: "", in: self)
    //                return
    //            }
    //            if (self.bankNo?.count)! < 6 {
    //               UIHelper.alertSimpleMessage(about: "银行卡号错误!", withDescription: "", in: self)
    //                return
    //            }
    //        }
    //
    //        if self.bankList?.count == 0{
    //            UIHelper.alertSimpleMessage(about: "数据异常!", withDescription: "", in: self)
    //            return
    //        }
    //        let money = Double(self.moneyCount!) ?? 0
    //       let min = Double(self.limitMin ?? "0") ?? 0
    //       let max = Double(self.limitMax ?? "0") ?? 0
    //        if money < min{
    //            UIHelper.alertSimpleMessage(about: "存款金额不能小于\(self.limitMin ?? "未知错误")!", withDescription: "", in: self)
    //            return
    //        }
    //
    //        if  money > max{
    //            UIHelper.alertSimpleMessage(about: "存款金额不能大于\(self.limitMax ?? "未知错误")!", withDescription: "", in: self)
    //            return
    //        }
    //
    //        let dict:[String:Any] = self.bankList![self.paySelectIndex]
    //       let logo = dict["logo"] as? String
    //        if logo == nil {
    //            UIHelper.alertSimpleMessage(about: "支付通道异常!", withDescription: "", in: self)
    //            return
    //        }
    //        if bankType == nil {
    //            UIHelper.alertSimpleMessage(about: "支付通道类型异常!", withDescription: "", in: self)
    //            return
    //        }
    //
    ////        if bankType == "23"{ //需要弹出支付提示要余额带小数点
    ////            if self.isShowPop == true{ //是否需要弹出
    ////                if self.moneyCount!.contains(".") == false { //金额不为整数
    ////                    self.isShowPop = false
    ////                    PopWindowHelper.showPayHintPopView(title: "支付提示", subTitle: "请输入带有小数点的金额，例如\n【200.15】【500.45】【2000.89】")
    ////                    return
    ////                }
    ////            }
    ////        }
    //
    //        self.showLoadHUD(title: "提交中...")
    //        NetWorkRequest(API.submitDeposits(url: "95b1768", amount: self.moneyCount!, bankOption: String("\(String(logo!) ?? "")|\(bankType ?? "")"), bankDetails: self.bankDetails!,ccToken: API.getCcToken(), vcToken: API.getVcToken(),isbq:dict["isbq"] as? String ?? "0", payCardNumber: self.bankNo ?? "", payUserName: self.realName ?? "" ), completion: {  (responseData,statusCode,strData) -> (Void) in
    //            self.dismissLoadHUD()
    //           // self.isShowBankInfoPop = true
    //
    //            let dataDict = responseData.dictionaryObject
    //        //    let dict :[String:Any] = JSON(parseJSON: dataDict?["data"] as? String ?? "").dictionaryObject!
    //            let dict :[String:Any] = dataDict?["data"] as? [String : Any] ?? [:]
    //             let method = dict["method"] as? Int ?? -1
    //            if String("\(String(logo!) ?? "")|\(self.bankType ?? "")") == "logo-PAYCARD|6"{ //需要弹出支付卡信息提示
    //                self.params = dict["params"] as?  [String : Any] ?? [:]
    //                if self.isBack == false{
    //                    self.showBankInfoPopView()
    //                }
    //            }else{
    //                if method == 1{ //生成二维码
    //                    UIHelper.alertSimpleMessage(about: "App当前版本不支持这种支付类型 \(method)!", withDescription: "", in: self)
    //                }else if method == 2{//跳转到三方的网址
    //                    let urlString = dict["url"] as? String
    //                    if urlString != nil{
    //                        if let url = URL(string: urlString ?? "") {
    //                            //根据iOS系统版本，分别处理
    //                            if #available(iOS 10, *) {
    //                                UIApplication.shared.open(url, options: [:],
    //                                                          completionHandler: {
    //                                                            (success) in
    //                                })
    //                            } else {
    //                                UIApplication.shared.openURL(url)
    //                            }
    //                        }
    //                    }else{
    //                        UIHelper.alertSimpleMessage(about: "当前跳转地址异常 \(method)!", withDescription: "", in: self)
    //                    }
    //
    //
    ////                    if url != nil{
    ////                        self.navigationController?.navigationItem.backBarButtonItem?.title = ""
    ////                        let vc =  WebViewController()
    ////                        //  vc.isBackHome = true
    ////                        vc.view.backgroundColor = UIColor.white
    ////                        vc.url = url
    ////                        vc.navigationController?.navigationItem.backBarButtonItem?.title = ""
    ////                        vc.isShowRefresh = false
    ////                        //    vc.isBack = true
    ////                        self.navigationController?.pushViewController(vc, animated: true);
    ////                    }else{
    ////                        UIHelper.alertSimpleMessage(about: "当前跳转地址异常 \(method)!", withDescription: "", in: self)
    ////                    }
    //                }else if method == 3{ //post请求提交
    //                    let url = dict["url"] as? String
    //                    if url != nil{
    //                        let array : Array = url!.components(separatedBy: "&")
    //                        if array.count >= 2{
    //                            var base64Url = array[0].replacingOccurrences(of: "url=", with: "")
    //                            var base64Params = array[1].replacingOccurrences(of: "params=", with: "")
    //                            if base64Url.count>0&&base64Url.count%4 != 0{
    //                                let urlNum = base64Url.count%4
    //                                for _ in 0 ... (4-urlNum){
    //                                    base64Url.append("=")
    //                                }
    //                            }
    //
    //                            let decodedUrlData = NSData(base64Encoded: base64Url, options: NSData.Base64DecodingOptions(rawValue: 0))
    //                            if decodedUrlData != nil {
    //                                let decodedUrl = NSString(data: decodedUrlData! as Data, encoding: String.Encoding.utf8.rawValue)
    //                                if base64Params.count>0&&base64Params.count%4 != 0{
    //                                    let paramsNum = base64Params.count%4
    //                                    for _ in 0 ... (4-paramsNum){
    //                                        base64Params.append("=")
    //                                    }
    //                                }
    //                                let decodedParamsData = NSData(base64Encoded: base64Params, options: NSData.Base64DecodingOptions(rawValue: 0))
    //                                if decodedParamsData != nil{
    //                                    let decodedParams = NSString(data: decodedParamsData! as Data, encoding: String.Encoding.utf8.rawValue)
    //
    //                                    UserDefaults.standard.set(decodedUrl, forKey: DefaultKey.THIRD_PARTY_DOMAIN)
    //                                    let paramsDict  =  JSON.init(parseJSON: decodedParams! as String).dictionaryObject
    //                                    if paramsDict == nil{
    //                                        UIHelper.alertSimpleMessage(about: "json数据解析异常!", withDescription: "", in: self)
    //                                    }else{
    //                                        self.showLoadHUD(title: "请求数据...")
    //                                        NetWorkRequest(API.requsetThirdParty(params: paramsDict!), completion: { (responseData,statusCode,strData) -> (Void) in
    //                                            self.dismissLoadHUD()
    //                                        }, failed: { (faildInfo,reCode,msg) -> (Void) in
    //                                            DispatchQueue.main.async {
    //                                                self.dismissLoadHUD()
    //                                                if reCode == "-1"{
    //                                                    self.navigationController?.navigationItem.backBarButtonItem?.title = ""
    //                                                    let vc = HtmlWebVC()
    //                                                    vc.navigationController?.navigationItem.backBarButtonItem?.title = ""
    //                                                    vc.htmlDataStr = faildInfo
    //                                                    self.navigationController?.pushViewController(vc, animated: true)
    //                                                }else{
    //                                                    UIHelper.alertSimpleMessage(about: "\(faildInfo)", withDescription: "", in: self)
    //                                                }
    //
    //                                            }
    //                                        }, errorResult: {() -> (Void) in
    //                                            DispatchQueue.main.async {
    //                                                self.dismissLoadHUD()
    //                                                UIHelper.alertSimpleMessage(about: "第三方网络请求异常!", withDescription: "", in: self)
    //                                            }
    //                                        })
    //                                    }
    //                                    print("\(decodedUrl ?? "异常")---\(decodedParams ?? "异常")---\(paramsDict)")
    //                                }else{
    //                                    UIHelper.alertSimpleMessage(about: "参数数据解析异常!", withDescription: "", in: self)
    //                                }
    //                            }else{
    //                                UIHelper.alertSimpleMessage(about: "地址数据解析异常!", withDescription: "", in: self)
    //                            }
    //
    //
    //                        }else{
    //                            UIHelper.alertSimpleMessage(about: "数据处理异常!", withDescription: "", in: self)
    //                        }
    //                    }else{
    //                        UIHelper.alertSimpleMessage(about: "url地址异常!", withDescription: "", in: self)
    //                    }
    //                }else if method == 4{//跳转到三方的网址
    //                    UIHelper.alertSimpleMessage(about: "App当前版本不支持这种支付类型 \(method)!", withDescription: "", in: self)
    //                }else{
    //                    UIHelper.alertSimpleMessage(about: "支付类型异常!", withDescription: "", in: self)
    //                }
    //
    //            }
    //
    //        }, failed: { (faildInfo,reCode,msg) -> (Void) in
    //            DispatchQueue.main.async {
    //                self.dismissLoadHUD()
    //                if reCode == "21002"{
    //                    UIHelper.displayLoginExpireTip(self)
    //                }else{
    //                    UIHelper.alertSimpleMessage(about: "\(faildInfo)", withDescription: "", in: self)
    //                }
    //            }
    //
    //        }) { () -> (Void) in
    //            DispatchQueue.main.async {
    //                self.dismissLoadHUD()
    //                 UIHelper.alertSimpleMessage(about: "提交玩家存款异常!", withDescription: "", in: self)
    //            }
    //
    //        }
    //    }
    
    
    //显示卡信息
    func showBankInfoPopView(){
        let bgView :UIControl  = UIControl.init()
        bgView.backgroundColor = RGBAlpa(1,1,1,0.4)
        bgView.tag = 1009
        bgView.isUserInteractionEnabled = true
        // bgView.addTarget(self, action: #selector(self.actionToCancelBankInfo), for: .touchUpInside)
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        window.addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
        }
        
        let whiteView :UIView  = UIView.init(frame: UIScreen.main.bounds)
        whiteView.backgroundColor = UIColor.init(white: 1, alpha: 1)
        whiteView.layer.cornerRadius = 5;
        whiteView.layer.masksToBounds = true
        bgView.addSubview(whiteView)
        whiteView.snp.makeConstraints { (make) in
            make.width.equalTo(280)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview()
            make.height.equalTo(350.5)
        }
        
        let  titleBtn : UIButton  = UIButton.init(type: .custom)
        titleBtn.setBackgroundImage(imageNamed("icon_common_pop_window_title_bg"), for: .normal)
        titleBtn.setTitle("订单已提交", for: .normal)
        titleBtn.adjustsImageWhenHighlighted = false
        titleBtn.titleEdgeInsets = UIEdgeInsets(top: -10,left: 0, bottom: 0, right: 0)
        whiteView.addSubview(titleBtn)
        titleBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(59)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
        }
        
        let closeBtn : UIButton  = UIButton.init(type: .custom)
        closeBtn.setImage(imageNamed("icon_popwindows_close"), for: .normal)
        closeBtn.adjustsImageWhenHighlighted = false
        closeBtn.addTarget(self, action: #selector(self.actionToCancelBankInfo), for: .touchUpInside)
        whiteView.addSubview(closeBtn)
        closeBtn.snp.makeConstraints { (make) in
            make.width.equalTo(14)
            make.height.equalTo(14)
            make.right.equalToSuperview().offset(-10)
            make.top.equalToSuperview().offset(10)
        }
        
        let bankList = GlobalInfo.bankList
        let payToBank = "logo-\(self.params?["payToBank"] as? String ?? "")"
        var bankImage : String = ""
        var bankName :String = self.params?["payToBank"] as? String ?? ""
        if bankList != nil {
            for  (_ ,dict) in (bankList?.enumerated())!{
                let banklogo = dict["logo"] as? String ?? ""
                //      bankcode = bankcode.uppercased()
                if payToBank == banklogo{
                    bankImage = dict["image"] as? String ?? ""
                    bankName = dict["name"] as? String ?? ""
                    break
                }
            }
        }
        
        let content =  UILabel.init()
        content.text = "请充值到下列存款账号中"
        content.textColor =  HexRGBAlpha(0x333333,1)
        content.textAlignment = .left
        content.font = UIFont.boldSystemFont(ofSize: 16)
        whiteView.addSubview(content)
        content.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(20)
            make.left.equalToSuperview().offset(12)
            make.top.equalTo(titleBtn.snp.bottom).offset(12)
        }
        let iconImageView = UIImageView.init()
        whiteView.addSubview(iconImageView) //124x25
        if bankImage != "" {
            iconImageView.sd_setImage(with: URL.init(string: bankImage)) { (img, error, type, url) in
                
            }
        }
        iconImageView.snp.makeConstraints { (make) in
            make.width.equalTo(30)
            make.height.equalTo(30)
            make.left.equalToSuperview().offset(12)
            make.top.equalTo(content.snp.bottom).offset(6)
        }
        
        let banknameLabel =  YTTCopyLabel.init()
        banknameLabel.text = bankName
        banknameLabel.textColor =  HexRGBAlpha(0x333333,1)
        banknameLabel.textAlignment = .left
        banknameLabel.font = UIFont.systemFont(ofSize: 14)
        whiteView.addSubview(banknameLabel)
        banknameLabel.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-12)
            make.height.equalTo(20)
            make.left.equalTo(iconImageView.snp.right).offset(12)
            make.centerY.equalTo(iconImageView.snp.centerY)
        }
        //126 36
        //        iconImageView.sd_setImage(with: URL.init(string: "https://apimg.alipay.com/combo.png?d=cashier&t=" + (self.params?["payToBank"] as? String ?? ""))) { (img, error, type, url) in
        //
        //        }
        //        iconImageView.snp.makeConstraints { (make) in
        //            make.width.equalTo(124)
        //            make.height.equalTo(25)
        //            make.left.equalToSuperview().offset(12)
        //            make.top.equalTo(content.snp.bottom).offset(12)
        //        }
        // self.params
        let nameLabel =  YTTCopyLabel.init()
        nameLabel.text = "姓名：\(self.params?["payToUserName"] as? String ?? "")"
        nameLabel.textColor =  HexRGBAlpha(0x666666,1)
        nameLabel.textAlignment = .left
        nameLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString = nameLabel.attributedTextColorWithString(string: nameLabel.text! as NSString, subString:"姓名：", color: HexRGBAlpha(0x333333,1))
        nameLabel.attributedText = attributedString
        whiteView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(20)
            make.left.equalToSuperview().offset(12)
            make.top.equalTo(iconImageView.snp.bottom).offset(6)
        }
        
        let numberLabel =  YTTCopyLabel.init()
        numberLabel.text = "账号：\(self.params?["payToCardNumber"] as? String ?? "")"
        numberLabel.textColor =  HexRGBAlpha(0x666666,1)
        numberLabel.textAlignment = .left
        numberLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString2 = numberLabel.attributedTextColorWithString(string: numberLabel.text! as NSString, subString:"账号：", color: HexRGBAlpha(0x333333,1))
        numberLabel.attributedText = attributedString2
        whiteView.addSubview(numberLabel)
        numberLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(20)
            make.left.equalToSuperview().offset(12)
            make.top.equalTo(nameLabel.snp.bottom)
        }
        
        let moneyLabel =  YTTCopyLabel.init()
        moneyLabel.text = "金额：\(self.moneyCount ?? "")"
        moneyLabel.textColor =   HexRGBAlpha(0x666666,1)
        moneyLabel.textAlignment = .left
        moneyLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString3 = moneyLabel.attributedTextColorWithString(string: moneyLabel.text! as NSString, subString:"金额：", color: HexRGBAlpha(0x333333,1))
        moneyLabel.attributedText = attributedString3
        whiteView.addSubview(moneyLabel)
        moneyLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(20)
            make.left.equalToSuperview().offset(12)
            make.top.equalTo(numberLabel.snp.bottom)
        }
        
        
        let addressLabel =  YTTCopyLabel.init()
        addressLabel.text = "地址：\(self.params?["payToBank"] as? String ?? "")"
        addressLabel.textColor =   HexRGBAlpha(0x666666,1)
        addressLabel.textAlignment = .left
        addressLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString4 = moneyLabel.attributedTextColorWithString(string: addressLabel.text! as NSString, subString:"地址：", color: HexRGBAlpha(0x333333,1))
        addressLabel.attributedText = attributedString4
        whiteView.addSubview(addressLabel)
        addressLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(20)
            make.left.equalToSuperview().offset(12)
            make.top.equalTo(moneyLabel.snp.bottom)
        }
        
        let remarkLabel =  YTTCopyLabel.init()
        remarkLabel.text = "附言：\(self.params?["payAttach"] as? String ?? "")(仅能使用一次)"
        remarkLabel.textColor =  UIColor.red
        remarkLabel.textAlignment = .left
        remarkLabel.font = UIFont.systemFont(ofSize: 14)
        var attributedString5 = remarkLabel.attributedTextColorWithString(string: remarkLabel.text!  as NSString, subString:"(仅能使用一次)", color: HexRGBAlpha(0x666666,1))
        //   attributedString5 = remarkLabel.attributedTextColorAddWithAttributedString(attributedString: attributedString5, string: remarkLabel.text! as NSString, subString: "附言：", color: HexRGBAlpha(0x333333,1))
        remarkLabel.attributedText = attributedString5
        whiteView.addSubview(remarkLabel)
        remarkLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(20)
            make.left.equalToSuperview().offset(12)
            make.top.equalTo(addressLabel.snp.bottom)
        }
        
        let hintLabel =  UILabel.init()
        hintLabel.text = "1：请在转帐过程中，正确填写附言，便于快速核对你的存款记录"
        hintLabel.textColor =  HexRGBAlpha(0x666666,1)
        hintLabel.textAlignment = .left
        hintLabel.numberOfLines = 2
        hintLabel.font = UIFont.systemFont(ofSize: 14)
        whiteView.addSubview(hintLabel)
        hintLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(40)
            make.left.equalToSuperview().offset(12)
            make.top.equalTo(remarkLabel.snp.bottom)
        }
        
        let cancelBtn : UIButton  = UIButton.init(type: .custom)
        cancelBtn.setTitle("跳转到网银去支付", for: .normal)
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: 280-20, height: 40)
        cancelBtn.layer.addSublayer(layerGradient)
        cancelBtn.layer.cornerRadius = 5;
        cancelBtn.layer.masksToBounds = true
        cancelBtn.addTarget(self, action: #selector(self.actionToPaySubmit), for: .touchUpInside)
        cancelBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        whiteView.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(40)
            make.centerX.equalToSuperview()
            make.top.equalTo(hintLabel.snp.bottom).offset(12)
        }
        
    }
    
    //取消
    @objc func actionToCancelBankInfo(){
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        window.viewWithTag(1009)?.removeFromSuperview()
    }
    
    @objc func actionToPaySubmit() -> Void {
        //        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        //        window.viewWithTag(1009)?.removeFromSuperview()
        let urlString = self.params?["payToUrl"] as? String ?? ""
        if urlString != "" {
            if let url = URL(string: urlString) {
                //根据iOS系统版本，分别处理
                if #available(iOS 10, *) {
                    UIApplication.shared.open(url, options: [:],
                                              completionHandler: {
                                                (success) in
                    })
                } else {
                    UIApplication.shared.openURL(url)
                }//95670676
            }
        }else{
            UIHelper.alertSimpleMessage(about: "跳转网银地址异常!", withDescription: "", in: self)
        }
        //        self.navigationController?.navigationItem.backBarButtonItem?.title = ""
        //        let vc =  WebViewController()
        //        vc.view.backgroundColor = UIColor.white
        //        vc.url = self.params?["payToUrl"] as? String ?? ""
        //        print("\(self.params?["payToUrl"] as? String ?? "")")
        //        vc.navigationController?.navigationItem.backBarButtonItem?.title = ""
        //        vc.isShowRefresh = false
        //        self.navigationController?.pushViewController(vc, animated: true);
        
    }
}
